// 封装分类业务相关代码
// 分类逻辑
import { onMounted, ref } from 'vue'
import {getCategoryService} from '@/api/category'
import { onBeforeRouteUpdate, useRoute } from 'vue-router';
export function useCategory() {
    const categoryList = ref({})
const route = useRoute()
const getCategories = async (id = route.params.id ) => {
  const res = await getCategoryService(id)
  categoryList.value = res
}
onMounted( () => {
    getCategories()
})
onBeforeRouteUpdate((to) => {
    getCategories(to.params.id)
  })
  return {
    categoryList
  }
}